<?php

function formateSelectAll($tabResultat){
// GERER SI LE TABLEAU EST VIDE !!! A FAIRE !!!!!	
	$retour ='[';
	foreach($tabResultat as $result){
		$retour.='[';		
		foreach($result as $k => $v){
			$retour.='"'.$v.'",';
		}
		$retour=substr($retour,0,-1);
		$retour.='],';
	}
	$retour=substr($retour,0,-1);
	$retour.=']';

	return $retour;
}

function showALLUsers()
{
	require('../config/connexion_db.config.php');

	$reponse = $connexion->query("SELECT * FROM users") or die(print_r($connexion->errorInfo()));
	$url = "ficheIdentite.php?idFiche=";
	while ($data = $reponse->fetch()) {
		echo "
		<tr>
			<td class='with-checkbox'>
				<input type='checkbox' name='check' value='1'>
			</td>
			<td>".$data['nom']."</td>
			<td>".$data['prenom']."</td>";
			if ($data['etat_versement'] == 'ok'){
			echo"	
				<td class='hidden-350'>
					<span class='label label-satgreen'>Active</span>
				</td>";
			}
			else
			{
				echo "
				<td class='hidden-350'>
					<span class='label label-lightred'>Inactive</span>
				</td>";				
			}
	 	echo "
	 	<td class='hidden-1024'>".date('d-m-Y', strtotime($data['date_ins']))."</td>
			<td class='hidden-480'>
			<a class='btn' rel='tooltip' title='View' onclick='window.open(\"".$url.$data['id']."\",\"width=400px\",\"height=500px\")'>
				<i class='fa fa-search'></i>
			</a>
			<a href='../_ajax/supprimeFiche.php?id=".$data['id']."' class='btn' rel='tooltip' title='Delete'>
				<i class='fa fa-times'></i>
			</a>
			</td>
		</tr>";
	}
}

function showLastUsers($time)
{	
	require('../config/connexion_db.config.php');
	$date = date('d/m/Y', $time);
	$reponse = $connexion->query("SELECT * FROM users WHERE date_ins >= '".$date."'") or die(print_r($connexion->errorInfo()));

	echo "<table class='table table-hover table-nomargin'>
	<thead>
	<tr>
	<th>Titre</th>
	<th>Nom</th>
	<th class='hidden-350'>Prenom</th>
	<th class='hidden-1024'>Etat versement</th>
	</tr>
	</thead>
	<tbody>";
	while ($data = $reponse->fetch()) {
		echo "	<tr>
		<td>".$data['titre']."</td>
		<td>".$data['nom']."</td>
		<td class='hidden-350'>".$data['prenom']."</td>
		<td class='hidden-1024'>";
		if ($data['etat_versement'] == 'ok')
			echo "<span class='label label-satgreen'>Active</span>";
		else
				echo "<span class='label label-lightred'>Inactive</span>";
		echo "</td>
		</tr>";
	}

	echo"</tbody>
	</table>";
}

function showUserFromId($id)
{
	require('../config/connexion_db.config.php');

	$reponse = $connexion->query("SELECT * FROM users WHERE created_at >= '".$time."'") or die(print_r($connexion->errorInfo()));

	echo "<table class='table table-hover table-nomargin'>

	<tbody>";
	while ($data = $reponse->fetch()) {
		echo "	<tr>
		<td>Nom</td>
		<td>".$data['nom']."</td>
		</tr>";
	}

	echo"</tbody>
	</table>";
}

?>
